<?php
if (!class_exists('DatabaseManager')) {
	/**
	 *  Manager class for database operations
	 *	@author Alecsandru Gabriel DINU
	 *  @since Jun 18, 2008
	 */
	class DatabaseManager {
		private $config = null; 
		
		/**
		 * Class constructor
		 * @access public
		 */
		public function __construct() {
			$this->config = AlfaConfiguration::getInstance();
		}
		
		/**
		 * Execute a Propel build command
		 * @access public
		 * @param string
		 */
		public function execute($command) {
			$orm = $this->config->getString("database/orm", "propel");
 			if ($orm == "propel") {
	    		$dao = new PropelTemplate();
 			} else if ($orm == "doctrine") {
 				$dao = new DoctrineTemplate();
			} else if ($orm == "ezpdo") {
				$dao = new EzpdoTemplate();
			}
	    	$dao->execute($command);
		}
		
		/**
		 * This method is used to transform a DB4 Designer
		 * to Propel schema file.
		 * DB4 Designer was replaced by MySQL Workbench, so
		 * this method is no longer used.
		 * 
		 * It's here only to serve as an example.
		 * @access public
		 * @param string 
		 * @param string
		 * @throws ConfigurationException
		 */
		public function importDbDesigner4Model($model, $schema) {
			$orm = $this->config->getString("database/orm", "propel");
			if ($orm != "propel") {
				throw new ConfigurationException("This method is available only for propel orm.");				
			}
	    	$dao = new PropelTemplate();
	    	$dao->dbd2propel($model, $schema);
		}
		
	}
}
?>